package com.gitee.wsl.doc.html.readability4j.extended


import com.gitee.wsl.doc.html.readability4j.Readability4J
import com.gitee.wsl.doc.html.readability4j.Readability4JTest
import com.gitee.wsl.doc.html.readability4j.model.PageTestData
import com.gitee.wsl.doc.html.readability4j.model.ReadabilityOptions


open class Readability4JExtendedTest : Readability4JTest() {

    override fun createReadability4J(url: String, testData: PageTestData): Readability4J {
        // Provide one class name to preserve, which we know appears in a few
        // of the test documents.
        return Readability4JExtended(url, testData.sourceHtml,
            ReadabilityOptions(additionalClassesToPreserve = listOf("caption"))
        )
    }

    override fun loadTestData(testPageFolderName: String, pageName: String): PageTestData {
        var testData = super.loadTestData(testPageFolderName, pageName)

        try {
            // check if test case has a different expected output placed in expected-extended.html
            val expectedExtendedOutput = getFileContentFromResource(testPageFolderName, pageName, "expected-extended.html")

            testData = PageTestData(testData.pageName, testData.sourceHtml, expectedExtendedOutput, testData.expectedMetadata)
        } catch(ignored: Exception) { }

        return testData
    }
}